package com.zyy.joseata.mq;

import com.zyy.joseata.util.ThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;

import java.nio.charset.StandardCharsets;

/**
 * @author zhangyy
 */
@Slf4j
public class JoSeataRabbitListenerMessageProcess implements MessagePostProcessor {

    @Override
    public Message postProcessMessage(Message message) throws AmqpException {

        ThreadLocalUtil.setTxId(message.getMessageProperties().getMessageId());

        log.info("MessageProcess => ThreadName:{}, 拦截的数据:{}, 设置的txId:{}",Thread.currentThread().getName(),new String(message.getBody(), StandardCharsets.UTF_8), ThreadLocalUtil.getTxId());

        return message;
    }
}
